const config = getApp().globalData.config
const T = getApp().globalData.T
function uploadImg(that, ty, ele) {
  let url = config.host + 'admin/file/singleFile';
  return new Promise((resolve, reject) => {
    wx.chooseImage({
      count: 1,
      success: (res) => {
        that.setData({ [ele]: true });
        let path = res.tempFilePaths[0];
        T.onUploadFile(url, path, 'file', {
          type: ty
        }, (_res) => { // success
          that.setData({ [ele]: false })
          resolve(_res.data.url);
        }, (_fail) => { // fail
          console.log(_fail)
          T.toast({
            id: '#toast',
            text: '上传图片失败,请重新上传'
          });
        })
      },
    })
  })
}

export default uploadImg;